{%extends "admin/base.html"%}
{%import "_pagination.html" as page_macros%}
{%block title%}
用户- {{site["name"]|upper}}
{%endblock title%}

{%block metas%}
{{super()}}
{%endblock metas%}
{%block styles%}
{%if config.get("DEBUG")%}
{%include "_common-css.html"%}
<link rel="stylesheet" href="{{url_for("static", filename="css/admin/user.css")}}">
{%else%}
<link rel="stylesheet" href="{{url_for("static", filename="dist/css/user.min.css")}}">
{%endif%}

{{super()}}
{%endblock styles%}

{%block content%}

{%include "admin/_sidebar.html"%}

<div class="main">
    <div class="main-wraper">
        {%include "admin/_head.html"%}
    <div class="main-content">
        <div class="panel">
            <div class="panel-body user-panel">
                {%for msg in get_flashed_messages()%}
                {%if loop.first%}
                <div class="alert {%if error%}alert-danger{%else%}alert-success{%endif%} alert-dismissible" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        {{msg.decode("utf-8")}}
                    </div>
                {%endif%}
                {%endfor%}
 
                <div class="panel-heading">
                <h3 class="title" >用户列表</h3>
                <a class="btn btn-default add-user" href="{{url_for("admin.user_new")}}">
                    <i class="fa fa-plus"></i>
                    添加用户</a>
                </div>
                <table class="table">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>用户名</th>
                            <th>昵称</th>
                            <th>书籍</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {%for user in users.items%}
                        <tr>
                            <th>{{user.id}}</th>
                            <th>
                                <a href="{{url_for("admin.user_detail", id=user.id)}}">{{user.username}}</a>
                            </th>
                            <th>
                                <a href="{{url_for("admin.user_detail", id=user.id)}}">{{user.nickname}}</a>
                            </th>
                            <td>{{user.count_book()}}</td>
                            <td>{{user.timestamp.strftime("%Y-%m-%d %H:%M:%S")}}</td>
                            <td>
                                <a href="{{url_for("admin.user_detail", id=user.id)}}">修改密码</a>
                            </td>
                        </tr>
                        {%endfor%}
                    </tbody>
                </table>
                {{page_macros.pagination_widget(users, "admin.user")}}
            </div>
        </div>
    </div>
    {%include "_footer.html"%}

    </div>


</div>

{%endblock content%}

{%block scripts%}

{%if config.get("DEBUG")%}
{%include "_common-js.html"%}
{%else%}
<script src="{{url_for("static", filename="dist/js/common.min.js")}}"></script>
{%endif%}

{{super()}}
{%endblock scripts%}


